package org.springblade.upgrade.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.upgrade.config.entity.PackageFrontConfig;
import org.springblade.upgrade.config.mapper.PackageFrontConfigMapper;
import org.springblade.upgrade.config.model.PackageFrontConfigBean;
import org.springblade.upgrade.config.service.IPackageFrontConfigService;
import org.springblade.upgrade.constant.QpBase64Util;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Version 1.0
 */
@Service
public class PackageFrontConfigServiceImpl extends BaseServiceImpl<PackageFrontConfigMapper, PackageFrontConfig> implements IPackageFrontConfigService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addData(PackageFrontConfigBean param) throws Exception {
        //保存
        PackageFrontConfig entity = param;
        return this.save(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateData(PackageFrontConfigBean param) throws Exception {
        //更新
        PackageFrontConfig newEntity = param;
        return this.updateById(newEntity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteData(PackageFrontConfigBean param) throws Exception {
        if (param.getIdList() != null && !param.getIdList().isEmpty()) {
            UpdateWrapper<PackageFrontConfig> del = new UpdateWrapper<>();
            del.lambda().in(PackageFrontConfig::getId, param.getIdList());
            return this.remove(del);
        }
        if (param.getId() != null) {
            return this.removeById(param.getId());
        }
        return true;
    }

    @Override
    public PackageFrontConfigBean findById(Long id) {
        PackageFrontConfigBean cond = new PackageFrontConfigBean();
        cond.setId(id);
        return findBySpec(cond);
    }

    @Override
    public PackageFrontConfigBean findBySpec(PackageFrontConfigBean param) {
        List<PackageFrontConfigBean> list = this.baseMapper.queryList(param);
        if (list == null || list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }

    @Override
    public List<PackageFrontConfigBean> findListBySpec(PackageFrontConfigBean param) {
        return this.baseMapper.queryList(param);
    }

    @Override
    public IPage<PackageFrontConfigBean> findPageBySpec(IPage<PackageFrontConfigBean> page, PackageFrontConfigBean param) {
        List<PackageFrontConfigBean> dataList = baseMapper.queryPageList(page, param);
        return page.setRecords(dataList);
    }

}

